import cgi
import os

from TopicDao import *

from google.appengine.ext.webapp import template
from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext import db

class EditTopicPage(webapp.RequestHandler):
    def post(self):
        
        topicDao = TopicDao()
        topic = topicDao.getTopic(self.request.get('content'))
        
        template_values = {'topicKey': topic[0].key(),
                           'content': topic[0].content,
                           }

        path = os.path.join(os.path.dirname(__file__), 'edittopic.html')
        self.response.out.write(template.render(path, template_values))
        
    
class PerformEdit(webapp.RequestHandler):
    def post(self):
        topic = db.get(self.request.get('topicKey'))
        topic.content = self.request.get('content')
        topic.put()
        self.redirect('/admin')